# -*- coding: utf-8 -*-
"""
Created on Wed Jul 10 20:53:03 2024

@author: LoongFly
"""

'''
# 闭运算
import cv2
import numpy as np

# img_read = cv2.imread("H:\\PycharmProjects\\OpenCV\\A3_Morphology\\photo\\zhiwen.bmp",cv2.IMREAD_UNCHANGED)
img_read = cv2.imread("A3_Morphology\\photo\\ganraotu.bmp",cv2.IMREAD_UNCHANGED)

kernel = np.ones((5, 5),np.uint8)

img_result = cv2.morphologyEx(img_read, cv2.MORPH_CLOSE, kernel)

cv2.imshow("Original", img_read)    #原始图像
cv2.imshow("CLOSE", img_result)     #闭运算图像

cv2.waitKey()
cv2.destroyAllWindows()

'''

# 闭运算加开运算
import cv2
import numpy as np

# img_read = cv2.imread("H:\\PycharmProjects\\OpenCV\\A3_Morphology\\photo\\zhiwen.bmp",cv2.IMREAD_UNCHANGED)
img_read = cv2.imread("A3_Morphology\\photo\\ganraotu.bmp",cv2.IMREAD_UNCHANGED)

kernel = np.ones((5, 5),np.uint8)
kernel2 = np.ones((7, 7),np.uint8)
# 图像处理
img_close = cv2.morphologyEx(img_read, cv2.MORPH_CLOSE, kernel)
img_close_open = cv2.morphologyEx(img_close, cv2.MORPH_OPEN, kernel2)   #对闭运算后的图像进行一次开运算
img_close_open_close = cv2.morphologyEx(img_close_open, cv2.MORPH_CLOSE, kernel2)

# 图像显示
cv2.imshow("Original", img_read)    #原始 图像
cv2.imshow("Close", img_close)      #闭运算 图像
cv2.imshow("Close_Open", img_close_open)      #闭运算+开运算 图像
cv2.imshow("Close_Open_Close", img_close_open_close)      #闭运算+开运算+闭运算 图像

cv2.waitKey()
cv2.destroyAllWindows()
